#include <time.h>
#include "surface.h"
#include <stdlib.h>
#include <iostream>
#include <string>

using namespace std;
int main(){
    char all_chess[2] = {'x','#'};
    surface all(30,140);
    surface_chessboard chessboard(30,100,all_chess,'+');
    surface_infoboard infoboard(30,40);
    chess_info info;
    int index = 0;
    int x,y;
    info.current_chess = all_chess[index];
    all.add_surface(30,100,0,0,chessboard.display_cache());
    infoboard.update_info(&info);
    all.add_surface(30,40,0,100,infoboard.display_cache());
    all.display();
    while(1){
        cout<<"for "<<all_chess[index]<<", please input x and y as 'x y' for the chess position:"<<endl;
        cin>>x>>y;
        info.current_chess = all_chess[index];
        info.current_x = x;
        info.current_y = y;
        chessboard.update_info(&info);
        all.add_surface(30,100,0,0,chessboard.display_cache());
        index ++;
        index %= 2;
        info.current_chess = all_chess[index];
        infoboard.update_info(&info);
        all.add_surface(30,40,0,100,infoboard.display_cache());
        all.display();
        int winner = chessboard.is_five_in_row();
        if(winner != -1){
            cout<<"the winner is "<<all_chess[winner]<<", congratulation!"<<endl;
            break;
        }
    }
    cout<<"pleas input ENTER to continue..."<<endl;
    getchar();
    //test2.display();

    return 0;
}
